package cn.itcast.spring.demo2;

import static org.junit.Assert.*;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BeanCreateTest {

	@Test
	public void getUserBean1() throws Exception {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		UserBean1 bean1 = (UserBean1) context.getBean("userBean1");
		UserBean1 bean2 = (UserBean1) context.getBean("userBean1");
		if(bean1 == bean2){
			System.out.println("我们是同一个对象");
		}else{
			System.out.println("我们不是同一个对象");
			
		}
		
		//bean.eat();
	}
	
	@Test
	public void getUserBean() throws Exception {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		UserBean2 bean = (UserBean2) context.getBean("userBean2Factory");
		bean.eat();
	}
	
	/**
	 * 通过实例工厂来创建对象
	 * @throws Exception
	 */
	@Test
	public void getUserBean3() throws Exception {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		UserBean3 bean = (UserBean3) context.getBean("userBean3");
		bean.eat();
	}
	

}
